home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / GraphicsWorkshop / Source / Converters / jpeg.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-14  |  8.1 KB  |  202 lines

  1. /*
  2.  * This is perhaps one of the most important objects. It's what deals with reading and
  3.  * writing the bitmaps to and from disk. When used init and free should always be called.
  4.  * The concept of sender is used in a couple of places in this object and should respond to
  5.  * the following request: It should respond to getImageCon and return the id of a ImageControl 
  6.  * object. Note that the NXBitmapImageRep links this from disk at run time. You may also
  7.  * do this, should you wish, or you may define your own set of internal routines. Whatever
  8.  * you do, the ImageControl object should respond to everything defined in image.h, and
  9.  * these should have predictable results.
  10.  */
  11.  
  12. #ifndef __PGMCONVERT__
  13. #define __PGMCONVERT__
  14.  
  15. #import <Converter.h>
  16.  
  17. #define CONVERT_ERR_NONE        0
  18. #define CONVERT_ERR_WARNING    1
  19. #define CONVERT_ERR_FATAL        2
  20.  
  21. #define ERROR_NO_ERROR            0
  22. #define ERROR_UNABLE_TO_OPEN    1
  23. #define ERROR_PERMISSION_DENIED    2
  24. #define ERROR_BAD_FORMAT        3
  25. #define ERROR_TRUNCATED_FILE    4
  26. #define ERROR_NEEDSWINDOWSERV    5
  27. #define ERROR_UNABLETOLINK        6
  28. #define ERROR_UNKNOWN            7
  29. #define ERROR_UNABLE_TO_WRITE    8
  30.  
  31. @interface JPEG : Converter
  32. {
  33. }
  34.  
  35. /*
  36.  * Initializes the object. This need not necessarily be used, but you can use it if you'd like.
  37.  * Assumes:     Nothing
  38.  * Returns:    self
  39.  * Results:    A new object is up and running.
  40.  */
  41. - init;
  42.  
  43. /*
  44.  * Frees anything used by the object.
  45.  * Assumes:    Object is instantiated.
  46.  * Results:     It is no longer valid to message the object.
  47.  */
  48. - free;
  49.  
  50. /*
  51.  * Reads the bitmap from stream. 
  52.  * Assumes:    The object has been instantiates, stream is an valid stream opened for at least
  53.  *            reading. Sender is the id of whatever object is calling the converter. 
  54.  * Returns:    id of an NXBitmapImageRep or nil if the image was unable to be read.
  55.  */
  56. - readFromStream: (NXStream *)stream from: sender;
  57.  
  58. /*
  59.  * Write the bitmaps id to stream.
  60.  * Assumes:    Object has been instantiated. At times, it's best to have used a call to the
  61.  *             save panel first, since this can set internal variables, but it's not necessary.
  62.  *            stream should be a valid NXStream opened for at least writing. Sender should
  63.  *            be the id of the caller. id is a NXBitmapImageRep, or something that responds
  64.  *            to all the message of the NXBitmapImageRep.
  65.  * Returns:    YES if the image was sucessfully writing, otherwise it returns NO.
  66.  */
  67. - (BOOL)write: (id)image toStream: (NXStream *)stream from: sender;
  68.  
  69. /*
  70.  * Similar to readFromStream but will read multiple images from a stream when present.
  71.  * Assumes:     Object instantiated. stream valid for reading. sender is id of caller.
  72.  * Returns:    id of an NXImage or nil if unable to read the image. It should return a single
  73.  *            image in the least, even for formats that don't support multiple images.
  74.  */
  75. - readAllFromStream: (NXStream *)stream from: sender;
  76.  
  77. /*
  78.  * Reverses the process of read all.
  79.  * Assumes:     Object instantiates. id is to an NXImage or something that responds to all of
  80.  *            NXImage's methods. stream is valid for writing. This should always attempt
  81.  *            to write at least one image to disk (the first usually) even for formats that 
  82.  *            don't support multiple images.
  83.  * Returns:    YES if the image is sucessfully written to disk.
  84.  */
  85. - (BOOL)writeAll: (id)image toStream: (NXStream *)stream;
  86.  
  87. /*
  88.  * Creates and lays out a custom view that the converter can use to set customization
  89.  * parameters. 
  90.  * Assumes:     Object instantiated and the window server is running. width should be the
  91.  *            maximum width the custom view can be.
  92.  * Returns:    id of a parent view or nil if this object doesn't use one.
  93.  */
  94. - customSaveView: (int)width;
  95.  
  96. /*
  97.  * This is very similar to customSaveView, however, it is used to set parameters for
  98.  * the run time loading of images. This object does not support input custom views.
  99.  * Assumes:     Object instantiated and the window server is running. width should be the
  100.  *            maximum width the custom view can be.
  101.  * Returns:    id of a parent view or nil if this object doesn't use one.
  102.  */
  103. - customOpenView: (int)width;
  104.  
  105. /*
  106.  * Returns the name of the current format, ie, the gif converter returns the string "Graphics
  107.  * Interchange Format (GIF)".
  108.  * Assumes:     Object has been instantiated.
  109.  * Returns:    A pointer to a string. The caller should always use something like strcpy to
  110.  *            get a copy of the string, since it's life is only guaranteed for the life of the
  111.  *            object.
  112.  */
  113. - (char *)getFormatName;
  114.  
  115. /*
  116.  * This is a simple interface to setting custom values of various parameters. There are
  117.  * no standards for what a converter must take of these values, so while the converter
  118.  * will tell you whether it took the value you or not, you, as the programmer, should
  119.  * not get upset when a parameter is not taken. Likewise, should the converter receive
  120.  * a request to set a parameter it does not understand, it should always refuse it with
  121.  * grace (ie, make it idiot proof.) What parameters an indivudual converter will take
  122.  * should be documented somewhere with the converters distribution.
  123.  * Assumes:    The converter is instantiated, parameter is a NULL terminated character
  124.  *            string, and ptr is a pointer to the data type. This is determined by patameter.
  125.  * Returns:    YES if the value was set, NO if the setting failed for any reason.
  126.  */
  127.  - (BOOL)setCustomParameter: (const char *)parameter withValue: (void *)ptr;
  128.  
  129. /*
  130.  * Gets a custom parameter value. See above about support for this call, as it's similar
  131.  * to setCustomParameter. Mainly, the converter should not crash when a request for
  132.  * a non-existant parameter is made.
  133.  * Assumes:     The converter is instantiated and parameter is a NULL terminater char-
  134.  *            acter string.
  135.  * Returns:    A pointer to the parameter (type depends on return value) or nil if the
  136.  *            parameter is not understood.
  137.  */
  138.  - (void *)getCustomParameter: (const char *)parameter;
  139.  
  140.  /*
  141.   * Returns a string with copyright information, name of the author, where the author
  142.   * can be reached, etc. This should only be a couple of lines, so keep it short and 
  143.   * sweet. An example might be:
  144.   * "My Image Format Converter\nby Joe Programmer\nCopyright R'N'R Software\n ...
  145.   * ... email bugs to jprogramm@system.there.edu"
  146.   * Assumes:     Converter linked and instantiated.
  147.   * Returns:    A pointer to a null terminated string. This string must be non volatile for
  148.   *             the life of the converter. Ie, as long as the programmer keeps a converter
  149.   *            linked, the pointer should be valid.
  150.   */
  151.  - (char *)copyrightNotice;
  152.  
  153.  /*
  154.   * Returns the current error state of the converter.
  155.   * Assumes:     Converter has been instantiated.
  156.   * Returns:    0 = CONVERT_ERR_NONE         Signals no error
  157.   *            1 = CONVERT_ERR_WARNING   Signals action taken, but not one expected.
  158.   *            2 = CONVERT_ERR_FATAL          Signals no action taken.
  159.   */
  160.  - (int)errorState;
  161.  
  162.  /*
  163.   * Returns an int describing the current error message.
  164.   * Assumes:    Converter instantiated.
  165.   * Returns:    An int describing the error type. See defines for integers returned.
  166.   */
  167.  - (int)errorMessage;
  168.  
  169.  /*
  170.   * This provides support for non standard error messages. It's preferable for programmers
  171.   * to avoid this message, but in special cases where you need to express something unique,
  172.   * it is appropiate. Just remember, that the use of this message disables multilingual
  173.   * support.
  174.   * Assumes:    Converter Instantiated
  175.   * Returns:    NULL terminated string describing the error.
  176.   */
  177.  - (char *)errorStringMessage;
  178.  
  179.  /*
  180.   * This method returns YES if the converter requires the window server. Ideally, converters
  181.   * should not depend on the window server, but sometimes this cannot be avoided. For 
  182.   * example, a programmer wouldn't be expect to write a PostScript interpreter just to read
  183.   * in eps files. Note, however, that returning YES will result in the converter not working
  184.   * with command line versions of applications.
  185.   * Assumes:    Converter Instantiated
  186.   * Returns:    YES is window server is needed, NO otherwise.
  187.   */
  188. - (BOOL)needsWindowServer;
  189.  
  190. /*
  191.  * Returns a string in the form <major version>.<minor version>. This is used by 
  192.  * the calling program to see what level or protocol the object will respond to. 
  193.  * Assumes:    Converter instantiated.
  194.  * Returns:    A null terminated string in the form <major version>.<minor version>.
  195.  *            For example, 1.0.
  196.  */
  197. - (char *)protocolVersion;
  198.  
  199. @end
  200.  
  201. #endif
  202.